﻿namespace Web.Control.WWW.Session
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Model.WWW_User.Teach;
    using BLF.WWW_User.Teach;
    using Lx.Web.Common.ControlsUI;
    using System.Collections.Generic;
    using System.Collections;
    using Model.WWW_User.User;
    public class sessionState3 : BaseControl
    {
        protected string Memberno = "";
        protected long sid = -1;
        protected SessionsModel sm = null;
        protected string IMAccount = "";
        protected string Timezone = "";
        protected DateTime dt = new DateTime();
        protected string StartTime = "";
        protected bool isshow = false;
        protected override void OnLoad(EventArgs e)
        {
            Memberno = HttpContext.Current.User.Identity.Name;
            ArrayList arrylist = new ArrayList();
            if (Memberno == "")
            {
                Page.Response.Redirect("/user/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri);
                return;
            }
            if (!string.IsNullOrEmpty(Request["sid"]))
            {
                long.TryParse(Request["sid"], out sid);
            }
            else
            {
                Response.End();
            }
          
                arrylist = Teach.GetSessionsState5(sid, Memberno);
                if (arrylist != null && arrylist.Count > 0)
                {
                    sm = arrylist[0] as SessionsModel;
                    IMAccount = (string)arrylist[1];
                    Timezone = arrylist[2].ToString() != "" ? arrylist[2].ToString() : "0";

                    if (sm.SessionID == sid) { isshow = true; }
                    if (isshow)
                    {
                        dt = Teach.ConvertTime(sm.StartDate, sm.StartTime, Timezone);
                        StartTime = dt.ToString("HH:mm");
                    }
                }
                else
                {
                    Response.End();
                }
            base.OnLoad(e);
        }
        protected string Getimtx(int i)
        {
            return BLF.WWW_User.Users.User.GetIMToolText(i.ToString());
        }
        protected string GetTedate(int let)
        {
            string va = "";
            DateTime mdt = DateTime.UtcNow.AddMinutes(double.Parse(Timezone));
            for (int i = 0; i <= let; i++)
            {
                DateTime dtt = mdt.AddDays((double)i);
                if (dt.ToString("yyyyMMdd") == dtt.ToString("yyyyMMdd"))
                {
                    va += "<option selected=\"selected\" value='" + dtt.ToString("yyyyMMdd") + "'>" + dtt.ToString("MMM d, yyyy", new System.Globalization.CultureInfo(Lx.Web.Common.UI.Globals.Language)) + "</option>";
                }
                else
                {
                    va += "<option  value='" + dtt.ToString("yyyyMMdd") + "'>" + dtt.ToString(TimeToString2, new System.Globalization.CultureInfo(Lx.Web.Common.UI.Globals.Language)) + "</option>";  
                }
            }
            return va;
        }
        
    }
}